﻿using System.Collections.Concurrent;
using GameFramework.common;

namespace Game.modules.player
{
    public class PlayerManager:Singleton<PlayerManager>
    {

        public ConcurrentDictionary<long, Player> players = new ConcurrentDictionary<long, Player>();

        public Player getPlayer(long playerId)
        {
            if (players.ContainsKey(playerId))
            {
                return players[playerId];
            }
            return null;
        }

        public void addPlayer(Player player)
        {
            if (players.ContainsKey(player.id))
            {
                UnityEngine.Debug.LogError("player already exist");
            }
            else
            {
                players.TryAdd(player.id, player);
            }
        }

        public void removePlayer(Player player)
        {
            if (players.ContainsKey(player.id))
            {
                players.TryRemove(player.id, out player);
            }
        }
    }
}